<template>
  <div>
    <el-calendar v-model="value">
      <template #dateCell="{ date, data }">
        <div class="date-content">
          <span class="text">{{ data.day.slice(-2) }}</span>
          <span :class="{ rest: isWeekends(date,data) }">
            {{ isWeekends(date,data)?'休':'' }}
          </span>
          <div class="lunar">{{ solarToLunar(date,data) }}</div>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
import { calendar } from '@/utils/calendar'
export default {
  name: 'Calender',

  data() {
    return {
      value: new Date()
    }
  },

  created() {

  },

  methods: {
    // 封装一个如果是周末就要加一个休的字
    // isWeekend(date) {
    //   return date.getDay() === 0 || date.getDay() === 6
    // },
    isWeekends(date, data) {
      // console.log(data.type)
      if (data.type === 'current-month') {
        return date.getDay() === 0 || date.getDay() === 6
      }
    },
    // 转农历的函数
    solarToLunar (slotDate, slotData) {
      const solarDayArr = slotData.day.split('-')
      // console.log(solarDayArr)

      const lunarDay = calendar.solar2lunar(solarDayArr[0], solarDayArr[1], solarDayArr[2])
      // 农历日期
      let lunarMD = lunarDay.IMonthCn + lunarDay.IDayCn
      if (lunarMD.includes('初一')) {
        // 每月初一 显示当前月 如正月初一 显示"正月"
        lunarMD = lunarMD.substr(0, 2)
      } else {
        // 每月初一以外 不显示当前月 如正月初十 显示"初十"
        lunarMD = lunarMD.slice(2)
      }
      // 公历节日\农历节日\农历节气
      let festAndTerm = []
      festAndTerm.push(lunarDay.festival == null ? '' : ' ' + lunarDay.festival)
      festAndTerm.push(lunarDay.lunarFestival == null ? '' : '' + lunarDay.lunarFestival)
      festAndTerm.push(lunarDay.Term == null ? '' : '' + lunarDay.Term)
      festAndTerm = festAndTerm.join('')
      let result = ''
      if (festAndTerm === '') {
        result = lunarMD
      } else {
        result = festAndTerm
      }
      return result
    }
  }
}
</script>
<style lang="scss" scoped>
.select-box {
  display: flex;
  // justify-content: flex-end;
}

::v-deep .el-calendar-day {
  height: auto;
  text-align: center;
}
::v-deep .el-calendar-table__row td::v-deep .el-calendar-table tr td:first-child,
::v-deep .el-calendar-table__row td.prev {
  border: none;
}
.date-content {
  display: flex;
  flex-direction:column  ;
  align-content: center;
  height: 40px;
  text-align: center;
  // line-height: 28px;
  font-size: 14px;
  position: relative;

  .lunar{
  // position: absolute;
  // bottom: 11px;
  // right: 5px;
  font-size: 9px;
  }
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 16px;
  height: 16px;
  line-height: 16px;
  display: inline-block;
  font-size: 10px;
  margin-left: 5px;
  position: absolute;
  left: 26px;
  margin-top: 5px;
}
.date-content .text {
  // width: 20px;
  // height: 20px;
  // line-height: 20px;
  display: inline-block;
}
::v-deep .el-calendar-table td.is-selected .text {
  // width: 20px;
  background: #409eff;
  color: #fff;
  border-radius: 50%;

}
::v-deep .el-calendar__header {
  display: none;
}
</style>
